package com.nowcoder.community.config;

import com.nowcoder.community.controller.interceptor.AuthInterceptor;
import com.nowcoder.community.controller.interceptor.LoginTicketInterceptor;
import com.nowcoder.community.controller.interceptor.ModelCookieInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class SpringMvcConfig implements WebMvcConfigurer {
    @Autowired
    ModelCookieInterceptor modelCookieInterceptor;

    @Autowired
    LoginTicketInterceptor loginTicketInterceptor;

    @Autowired
    AuthInterceptor authInterceptor;

    private static final String[] STATIC_RESOURCES = {
            "/**/*.css", "/**/*.js", "/**/*.jpg", "/**/*.png", "/**/*.jpeg"
    };

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(modelCookieInterceptor)
                .excludePathPatterns(STATIC_RESOURCES);

        registry.addInterceptor(loginTicketInterceptor)
                .excludePathPatterns(STATIC_RESOURCES);

        registry.addInterceptor(authInterceptor)
                .excludePathPatterns(STATIC_RESOURCES);
        WebMvcConfigurer.super.addInterceptors(registry);
    }
}
